﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace NczControlLibrary.Controls {
    public class AntiColorButton : Control {
        enum MyVisualState {
            nomal, mouseover, mouseleave, mouseleftbuttondown, mouseleftbuttonup,
        }
        public AntiColorButton() {
            this.DefaultStyleKey=typeof(AntiColorButton);
            this.Foreground=new SolidColorBrush(Colors.Gray);
            this.BorderBrush=new SolidColorBrush(Colors.Gray);
            this.Background=new SolidColorBrush(Colors.White);
            this.BorderThickness=new Thickness(1);
        }
        public override void OnApplyTemplate() {
            this.MouseEnter+=new MouseEventHandler(RdpPopButton_MouseEnter);
            this.MouseLeave+=new MouseEventHandler(RdpPopButton_MouseLeave);
            this.MouseLeftButtonDown+=new MouseButtonEventHandler(RdpPopButton_MouseLeftButtonDown);
            this.MouseLeftButtonUp+=new MouseButtonEventHandler(RdpPopButton_MouseLeftButtonUp);
            base.OnApplyTemplate();
        }

        void RdpPopButton_MouseLeftButtonUp(object sender,MouseButtonEventArgs e) {
            VisualStateManager.GoToState(this,MyVisualState.mouseleftbuttonup.ToString(),false);
        }

        void RdpPopButton_MouseLeftButtonDown(object sender,MouseButtonEventArgs e) {
            VisualStateManager.GoToState(this,MyVisualState.mouseleftbuttondown.ToString(),false);
        }
        /// <summary>
        /// 用户按下按钮事件
        /// </summary>
        public event MouseButtonEventHandler eClick { add { this.MouseLeftButtonUp+=value; } remove { this.MouseLeftButtonUp-=value; } }
        void RdpPopButton_MouseLeave(object sender,MouseEventArgs e) {
            VisualStateManager.GoToState(this,MyVisualState.nomal.ToString(),false);
            VisualStateManager.GoToState(this,MyVisualState.mouseleftbuttonup.ToString(),false);
        }

        void RdpPopButton_MouseEnter(object sender,MouseEventArgs e) {
            VisualStateManager.GoToState(this,MyVisualState.mouseover.ToString(),false);
        }
        #region dependency properties
        public static readonly DependencyProperty EntergroundProperty = DependencyProperty.Register("Enterground",typeof(Brush),typeof(AntiColorButton),new PropertyMetadata(
(o,k) => { }));
        public Brush Enterground { get { return (Brush)this.GetValue(EntergroundProperty); } set { this.SetValue(EntergroundProperty,value); } }
        public static readonly DependencyProperty TextProperty=DependencyProperty.Register("Text",typeof(string),typeof(AntiColorButton),new PropertyMetadata(
(o,k) => { }));
        public string Text { get { return (string)this.GetValue(TextProperty); } set { this.SetValue(TextProperty,value); } }
        #endregion
    }
}
